<template>
    <div class="oldversion">
        <Header :goback="goback" :title="'我的简历'"></Header>
        <div class="topheader page">
            <div class="nodata" v-if="isempty == false">
                <img :src="nodata_img" alt="">
                <label for="" class="font28">空空如也，请创建简历</label>
                <van-button class="createBtn font40 fontWhite bgBlueFC" @click="gocreate">创建简历</van-button>
            </div>
            <div v-else>
                <div class="itembox disFlex">
                    <div class="disFlex">
                        <label for="" class="font40 fontBlack2">自动推荐岗位</label>
                        <img :src="help_img" alt="" class="rightIcon1">
                    </div>
                    <van-switch v-model="checked" size="0.48rem" @update:model-value="onUpdateValue" />
                </div>
                <!-- 基础信息 -->
                <div class="baseInfo">
                    <div class="disFlex">
                        <div class="disFlex">
                            <label for="" class="font48 fontBlack2">{{ resumeInfo.realName }}</label>
                            <img :src="resumeInfo.sex == '0' ? sex_img[0] : sex_img[1]" alt="" class="rightIcon1">
                        </div>
                        <img :src="edit_img" alt="" class="rightIcon1" @click="topage('oldbase')">
                    </div>
                    <div class="textL fontBlack73 pt8">
                        <span class="font36">{{ resumeInfo.workingYear }}年经验 · {{ resumeInfo.age }}岁 ·
                            {{ resumeInfo.highestEducationText }}</span>
                        <span class="font36" v-if="resumeInfo.recruitmentText"> · {{ resumeInfo.recruitmentText
                        }}</span>
                    </div>
                    <div class="foldContent">
                        <div class="disFlex"><label for="">证件类型</label><label for="">大陆居民身份证</label></div>
                        <div class="disFlex"><label for="">证件号码</label><label for="">{{ resumeInfo.zjhm }}</label></div>
                        <div class="disFlex"><label for="">出生日期</label><label for="">{{ resumeInfo.birth }}</label>
                        </div>
                        <div class="disFlex"><label for="">求职状态</label><label for="">{{ resumeInfo.jobHuntStatus ==
                                '0' ? '在职' : resumeInfo.jobHuntStatus == '1' ? '待业' : ''
                        }}</label></div>
                        <div class="disFlex"><label for="">联系电话</label><label for="">{{ resumeInfo.mobile }}</label>
                        </div>
                        <div class="disFlex"><label for="">居住区域</label><label for="">{{ resumeInfo.liveArea }}</label>
                        </div>
                        <div class="disFlex"><label for="">详细地址</label><label for="" class="flex3 textR ml03">{{ resumeInfo.areaDetail }}</label>
                        </div>
                    </div>
                    <!-- <div class="foldBtn fontGrayB9 font24" @click="tofold"><span style="margin:0 0.16rem;">{{ is_fold ?
                            '更多信息' : '收起信息'
                    }}</span></div> -->
                </div>
                <!-- 自我评价 -->
                <div class="baseInfo listCon" v-if="resumeInfo.selfEvaluation">
                    <div class="disFlex">
                        <div class="font48 fontBlack2">自我评价</div>
                        <img :src="edit_img" alt="" class="rightIcon1" @click="topage('oldself')">
                    </div>
                    <div class="contentCon overDiv font40 textL fontBlack73">{{ resumeInfo.selfEvaluation }}</div>
                </div>
                <BaseInfo v-else :title="'自我评价'" :right_icon="add_circle_img" :content="resumeInfo.appraise"
                    @click="topage('oldself')" :isold="true"></BaseInfo>
                <!-- 求职意向 -->
                <div class="baseInfo listCon" v-if="resumeInfo.jobCategory">
                    <div class="disFlex">
                        <div class="font48 fontBlack2">求职意向</div>
                        <img :src="edit_img" alt="" class="rightIcon1" @click="topage('oldintention')">
                    </div>
                    <div class="contentCon textL ">
                        <div class="font40 fontBlack2 lh48">
                            <span class="font40 fontBlack2 lh48" style="margin-right:0.1rem">{{ resumeInfo.gw }}</span>
                            {{ resumeInfo.wageLower }}-{{ resumeInfo.wageUpper }}K
                        </div>
                        <div class="font36 fontBlack73 mtb" style="margin-top:0.08rem">{{ resumeInfo.liveArea }} {{ resumeInfo.hy }}
                            {{ resumeInfo.jobCategory == '0' ? '全职' : resumeInfo.jobCategory ==
                                    '1' ? '兼职' : resumeInfo.jobCategory == '2' ? '实习' : ''
                            }}</div>
                    </div>
                </div>
                <BaseInfo v-else :title="'求职意向'" :right_icon="ishaveinten ? edit_img : add_circle_img"
                    :content="resumeInfo.intro" :stitle="resumeInfo.duty" @click="topage('oldintention')" :isold="true">
                </BaseInfo>
                <!-- 工作经历 -->
                <BaseInfo v-if="resumeWorkRst == ''" :title="'工作经历'" :right_icon="add_circle_img"
                    :list="resumeInfo.old_company" @click="topage('oldexperience')"></BaseInfo>
                <div class="baseInfo listCon" v-else>
                    <div class="disFlex">
                        <div class="font48 fontBlack2">工作经历</div>
                        <img :src="add_circle_img" alt="" class="rightIcon1" @click="topage('oldexperience')">
                    </div>
                    <div class="contentCon font28 textL fontBlack73">
                        <div class="detailList" v-for="(itm, key) in resumeWorkRst.workInfoList" :key="key"
                            @click="toeditpage('oldexperience', itm.id)">
                            <div class="disFlex">
                                <div class="font44 fontBlack2">{{ itm.companyName }}</div>
                                <div class="disFlex ">
                                    <img src="../../assets/images/chevron-right.png" class="detailListIcon">
                                </div>
                            </div>
                            <div class="flexhor m1632">
                                <div class="font36 fontGrayB9">{{ itm.industry }}</div>
                                <div class="font36 fontGrayB9">{{ itm.startTime }}-{{ itm.endTime }}</div>
                            </div>
                            
                            <div class="font40 fontBlack73 overDiv workCon">
                                <div class="font40">工作内容：</div>
                                <div class="font40">{{ itm.workContents }}</div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 教育经历 -->
                <BaseInfo v-if="resumeEducationRst == ''" :title="'教育经历'" :right_icon="add_circle_img"
                    :list="resumeInfo.educate" @click="topage('oldeducation')"></BaseInfo>
                <div class="baseInfo listCon" v-else>
                    <div class="disFlex">
                        <div class="font48 fontBlack2">教育经历</div>
                        <img :src="add_circle_img" alt="" class="rightIcon1" @click="topage('oldeducation')">
                    </div>
                    <div class="contentCon font28 textL fontBlack73">
                        <div class="detailList" v-for="(itm, key) in resumeEducationRst.educationInfoList" :key="key"
                            @click="toeditpage('oldeducation', itm.id)">
                            <div class="disFlex">
                                <div class="font44 fontBlack2">{{ itm.graduateSchool }}</div>
                                <div class="disFlex">

                                    <img src="../../assets/images/chevron-right.png" class="detailListIcon">
                                </div>
                            </div>
                            <div class="flexhor mtb">
                                <div class="font36 fontGrayB9 ">
                                    <span class="font36">{{ itm.education }}</span>
                                    <span class="font36" v-if="itm.recruitment == 0">·非统招</span>
                                    <span class="font36" v-else-if="itm.recruitment == 1">·统招</span>
                                    <span class="font36" style="margin-left:0.08rem;"> {{ itm.profess }}</span>
                                </div>
                                <div class="font36 fontGrayB9">{{ itm.schoolTime }}-{{ itm.graduateTime }}</div>
                            </div>

                        </div>
                    </div>
                </div>
                <!-- 外语能力 -->
                <BaseInfo v-if="resumeLanguageRst == ''" :title="'外语能力'" :right_icon="add_circle_img"
                    :list="resumeInfo.language" @click="topage('oldlanguage')"></BaseInfo>
                <div class="baseInfo listCon" v-else>
                    <div class="disFlex">
                        <div class="font48 fontBlack2">外语能力</div>
                        <img :src="add_circle_img" alt="" class="rightIcon1" @click="topage('oldlanguage')">
                    </div>
                    <div class="contentCon font28 textL fontBlack73">
                        <div class="detailList" v-for="(itm, key) in resumeLanguageRst.languageInfoList" :key="key"
                            @click="toeditpage('oldlanguage', itm.id)">
                            <div class="disFlex">
                                <div class="font44 fontBlack2">{{ itm.language }}</div>
                                <div class="disFlex">
                                    <div class="font36 fontGrayB9">{{ itm.level }}</div>
                                    <img src="../../assets/images/chevron-right.png" class="detailListIcon">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 技能证书 -->
                <BaseInfo v-if="resumeSkillRst == ''" :title="'技能证书'" :right_icon="add_circle_img"
                    :list="resumeInfo.certificate" @click="topage('oldskill')"></BaseInfo>
                <div class="baseInfo listCon" v-else>
                    <div class="disFlex">
                        <div class="font48 fontBlack2">技能证书</div>
                        <img :src="add_circle_img" alt="" class="rightIcon1" @click="topage('oldskill')">
                    </div>
                    <div class="contentCon font28 textL fontBlack73">
                        <div class="detailList" v-for="(itm, key) in resumeSkillRst.skillInfoList" :key="key"
                            @click="toeditpage('oldskill', itm.id)">
                            <div class="disFlex">
                                <div class="font44 fontBlack2">{{ itm.certificateName }}</div>
                                <div class="disFlex">

                                    <img src="../../assets/images/chevron-right.png" class="detailListIcon">
                                </div>
                            </div>
                            <div class="flexhor">
                                <div class="font36 fontGrayB9 mtb">{{ itm.skillLevel }}</div>
                                <div class="font36 fontGrayB9">{{ itm.getTime }}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Header from '@/components/oldheader.vue'
import BaseInfo from '@/components/baseinfo.vue'
import { getCurrentInstance, reactive } from 'vue'
import educationVue from '../intention/education.vue'
export default {
    components: {
        Header,
        BaseInfo
    },
    data() {
        return {
            nodata_img: require('@/assets/images/empty.png'),
            help_img: require('@/assets/images/help-circle.png'),
            edit_img: require('@/assets/images/jump.png'),
            add_circle_img: require('@/assets/images/add-circle.png'),
            sex_img: [require('@/assets/images/sex.png'), require('@/assets/images/sex1.png')],
            checked: true,
            is_fold: true,//是否折叠
            // 基础信息（包括自我评价）
            resumeInfo: {},
            // 工作经历
            resumeWorkRst: {},
            // 教育经历
            resumeEducationRst: {},
            // 外语能力
            resumeLanguageRst: {},
            // 技能证书
            resumeSkillRst: {},
            // 岗位
            resumeIndustryInfoList: [],
            isempty: true,
            data: {},
            idcard: {}
        }
    },
    mounted() {
        this.api = getCurrentInstance().appContext.config.globalProperties.$http;
        this.idcard = this.$store.state.idCard;
        this.token = this.$store.state.token;
        var that = this;
        that.api.get('/personnel/h5/resumeInfo/queryOne', { identityNumber: that.idcard }).then(res => {
            var data = res.data;
            if (data.resumeInfo && JSON.stringify(data.resumeInfo) != '{}') {
                that.isempty = true;
                let data1 = data.resumeInfo;
                data1.age = that.getage(data1.identityNumber);
                data1.zjhm = that.replacepos(data1.identityNumber, 1, 17, '*');
                data1.birth = that.getbirth(data1.identityNumber);
                data1.mobile = data1.phoneNumber ? that.replacepos(data1.phoneNumber, 3, 7, '*') : '';
                if (data1.recruitment == 0) {
                    data1.recruitmentText = '非统招';
                } else if (data1.recruitment == 1) {
                    data1.recruitmentText = '统招';
                }
                that.resumeInfo = data1;
                this.geteducation(data1.highestEducation);
                that.getcity(data1.liveArea);
                // 是否自动推荐岗位
                that.checked = data1.recommendFlg == '1' ? true : false;

                // 求职意向
                that.resumeIndustryInfoList = data.resumeIndustryInfoList;
                // that.resumeInfo.gw = 'UI设计师';
                // that.resumeInfo.wageLower = '10k';
                // that.resumeInfo.wageUpper = '12k';
                // that.resumeInfo.jobCategory = '全职';
                // that.resumeInfo.hy = '互联网/电子商务';

                // that.resumeInfo.gw = '';
                // that.resumeInfo.wageLower = '';
                // that.resumeInfo.wageUpper = '';
                // that.resumeInfo.jobCategory = '';
                // that.resumeInfo.hy = '';
                that.getindustry(data1.profession.split(','));
                
                // 工作经验
                that.resumeWorkRst = data.resumeWorkRst;
                if (data.resumeWorkRst.workInfoList.length > 0) {
                    for (let i of data.resumeWorkRst.workInfoList) {
                        i.startTime = i.startTime.slice(0, 7).replace(/-/, '.');
                        i.endTime = i.endTime ? i.endTime.slice(0, 7).replace(/-/, '.') : '至今';
                    }
                }
                // 教育经历
                that.resumeEducationRst = data.resumeEducationRst;
                if (data.resumeEducationRst.educationInfoList.length > 0) {
                    for (let i of data.resumeEducationRst.educationInfoList) {
                        i.graduateTime = i.graduateTime.slice(0, 4);
                        i.schoolTime = i.schoolTime.slice(0, 4);
                    }
                }
                // 外语能力
                that.resumeLanguageRst = data.resumeLanguageRst;
                that.getlanguage();
                //技能证书
                that.resumeSkillRst = data.resumeSkillRst;
                if (data.resumeSkillRst.skillInfoList.length > 0) {
                    for (let i of data.resumeSkillRst.skillInfoList) {
                        i.getTime = i.getTime.slice(0, 7).replace(/-/, '.');
                    }
                }
                that.getskill();
                that.getpostdict();
                // 版本号 id
                that.data.version = data1.version;
                that.data.id = data1.id;

            } else {
                that.isempty = false;
            }
        });

    },
    created() {

    },
    methods: {
        goback() {
            this.$router.replace('/oldhome');
        },
        // 获取学历列表
        geteducation(highestEducation) {
            var that = this;
            that.maxList = [];
            that.api.get('/personnel/h5/resumeInfo/resumeEducation', {}).then(res => {
                var data = res.data.resumeEducation;
                for (let i = 0; i < data.length; i++) {
                    if (data[i].dictValue == highestEducation) {
                        that.resumeInfo.highestEducationText = data[i].dictLabel;
                    }
                    for (let j = 0; j < that.resumeEducationRst.educationInfoList.length; j++) {
                        if (that.resumeEducationRst.educationInfoList[j].education == data[i].dictValue) {
                            that.resumeEducationRst.educationInfoList[j].education = data[i].dictLabel;
                        }
                    }
                }
            })
        },
        // 区域列表
        getcity(liveVal) {
            var that = this;
            that.api.get('/personnel/h5/resumeInfo/getDeptTree', {}).then(res => {
                var data = res.data;
                for (let i in data) {
                    if (liveVal) {
                        if (i == liveVal) {
                            that.resumeInfo.liveArea = data[i];
                        }
                    }
                };
            })
        },
        gocreate() {
            this.$router.push('/oldresume')
        },
        onUpdateValue(e) {
            let data = {
                identityNumber: this.$store.state.token,
            }
            if (this.data.id) {
                data.id = this.data.id;
            }
            if (this.data.version + '') {
                data.version = this.data.version;
            }
            if (!e) {
                this.$dialog.alert({
                    title: '',
                    message: '关闭职位推荐后，将不会根据您的实际情况推荐匹配岗位',
                    confirmButtonText: '知道了',
                    confirmButtonColor: '#428FFC'
                }).then(() => {
                    this.checked = e;
                    var that = this;
                    data.recommendFlg = '0'
                    this.api.post('/personnel/h5/resumeInfo/addOrEditRecommendFlg', data).then(res => { })

                });
            } else {
                data.recommendFlg = '1'
                this.api.post('/personnel/h5/resumeInfo/addOrEditRecommendFlg', data).then(res => { })
            }

        },
        tofold() {
            this.is_fold = !this.is_fold
        },
        getage(IdCard) {
            var ageDate = new Date()
            var month = ageDate.getMonth() + 1
            var day = ageDate.getDate()
            var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1
            if (IdCard.substring(10, 12) < month || IdCard.substring(10, 12) === month && IdCard.substring(12, 14) <= day) {
                age++
            }
            if (age <= 0) {
                age = 1
            }
            return age;
        },
        getbirth(IdCard) {
            let birthday = IdCard.substring(6, 10) + "-" + IdCard.substring(10, 12) + "-" + IdCard.substring(12, 14);
            return birthday;
        },
        replacepos(text, start, stop, replacetext) {
            let cnt = ''
            for (let i = 0; i < (stop - start); i++) {
                cnt += replacetext;
            }
            let mystr = text.substr(0, start) + cnt + text.substr(stop);
            return mystr;
        },
        topage(page) {
            this.$router.push('/' + page)
        },
        getlanguage(type, level) {
            let that = this;
            let rllist = that.resumeLanguageRst.languageInfoList;

            // 语种
            that.api.get('/personnel/h5/resumeInfo/languageType', {}).then(res => {
                let data = res.data.languageType;
                if (that.resumeLanguageRst.languageInfoList.length > 0) {
                    for (let l = 0; l < that.resumeLanguageRst.languageInfoList.length; l++) {
                        for (let i = 0; i < data.length; i++) {
                            if (data[i].dictValue == that.resumeLanguageRst.languageInfoList[l].language) {
                                that.resumeLanguageRst.languageInfoList[l].language = data[i].dictLabel;
                            }
                        }
                    }
                }
                // 等级
                that.api.get('/personnel/h5/resumeInfo/languageLevel', {}).then(res => {
                    let data = res.data.languageLevel;
                    if (rllist.length > 0) {
                        for (let l = 0; l < rllist.length; l++) {
                            for (let i = 0; i < data.length; i++) {
                                if (data[i].dictValue == rllist[l].level) {
                                    rllist[l].level = data[i].dictLabel;
                                }
                            }
                        }
                    }
                })

            })

        },
        getskill() {
            let that = this;
            let skilllist = that.resumeSkillRst.skillInfoList;
            that.api.get('/personnel/h5/resumeInfo/skillLevel', {}).then(res => {
                let data = res.data.skillLevel;
                if (skilllist.length > 0) {
                    for (let l = 0; l < skilllist.length; l++) {
                        for (let i = 0; i < data.length; i++) {
                            if (data[i].dictValue == skilllist[l].skillLevel) {
                                skilllist[l].skillLevel = data[i].dictLabel;
                            }
                        }
                    }
                }
            })

        },
        getindustry(profession) {
            var that = this;
            that.api.get('/personnel/h5/resumeInfo/getIndustryTree', {}).then(res => {
                var data = res.data;
                var arr = [];
                data.forEach(el => {
                    el.children.forEach(val => {
                        profession.forEach(t => {
                            if (val.code == t) {
                                arr.push(val.chName);
                            }
                        })
                    })
                });
                that.resumeInfo.hy = arr.join('/')
            })
        },
        // 获取岗位下拉树
        getpostdict() {
            var that = this;
            var list = that.resumeIndustryInfoList;
            var list1 = that.resumeWorkRst.workInfoList;
            that.api.get('/personnel/h5/resumeInfo/getPostDictTree', {}).then(res => {
                var data = res.data;
                let arr = []
                if (list.length > 0) {
                    for (let l = 0; l < list.length; l++) {
                        data.forEach(el => {
                            el.children.forEach(el2 => {
                                el2.children.forEach(val => {
                                    if (val.code == list[l].twoLevel) {
                                        list[l].twoLevel = val.chName
                                        arr.push(val.chName)
                                    }
                                })
                            })
                        });
                    }
                    that.resumeInfo.gw = arr.join('/')
                }
                if(list1.length>0){
                    for (let l = 0; l < list1.length; l++) {
                        data.forEach(el => {
                            el.children.forEach(el2 => {
                                el2.children.forEach(val => {
                                    if (val.code == list1[l].industry) {
                                        list1[l].industry = val.chName
                                    }
                                })
                            })
                        });
                    }
                }
            })
        },
        toeditpage(page, params) {
            this.$router.push({ name: page, params: { id: params } })
        }


    }
}
</script>

<style scoped>
.nodata {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 1.6rem;
}

.baseInfo {
    padding: 0.36rem 0;
    padding-bottom: 0;
}

.baseInfo .pt8 {
    padding-top: 0.08rem;
}

.listCon {
    border-bottom: 0.02rem solid #E8E9EC;
}

.contentCon {
    margin: 0.2rem 0 0.5rem;
}

.overDiv {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.nodata img {
    width: 3.2rem;
    height: 3.2rem;
}

.nodata label {
    color: #B3B5B9;
    margin: 0.48rem 0 .64rem 0;
}

.createBtn {
    border-radius: 0.48rem;
    width: 1.92rem;
    height: 0.72rem;
}

.itembox {
    border-bottom: 0.02rem solid #E8E9EC;
    height: 1.22rem;
}

.rightIcon {
    width: 0.32rem;
    height: 0.32rem;
    margin-left: 0.06rem
}

.foldBtn {
    margin-top: 0.28rem;
    display: flex;
    flex-direction: row;
}

.foldBtn:before,
.foldBtn:after {
    content: "";
    flex: 1 1;
    border-bottom: 0.02rem solid #E8E9EC;
    margin: auto;
}

.foldContent {
    padding-bottom: 0.5rem;
    border-bottom: 0.02rem solid #E8E9EC;
}

.foldContent>div label:nth-child(1),
.foldContent>div label:nth-child(2) {
    font-size: 0.36rem;
    margin-top: 0.32rem;
}

.foldContent>div label:nth-child(1) {
    color: #B3B5B9;
}

.foldContent>div label:nth-child(2) {
    color: #363A44;
}

.detailList {
    margin-bottom: 0.32rem;
}

.detailListIcon {
    width: 0.48rem;
    height: 0.48rem;
}

.mtb {
    margin: 0.05rem 0 0.1rem
}

.workCon {
    line-height: 0.5rem;
}

.lh456 {
    line-height: 0.56rem;
}

.lh52 {
    line-height: 0.52rem;
}

.flexhor {
    display: flex;
    align-items: center
}

.flexhor div:nth-child(2) {
    margin-left: 0.48rem;
}
.m1632{
    margin-top: 0.16rem;
    margin-bottom: 0.32rem;
}
</style>